﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CROSLAND.BL.BE;
using System.Data.Common;
using System.Data;

namespace CROSLAND.DL.DALC.MSSQL
{
    public class PersonaDALC : BaseDALC, IPersonaDALC
    {      

        #region IPersonaDALC Members

        public List<PersonaBE> listarVendedores()
        {
            throw new NotImplementedException();
        }

        public List<PersonaBE> listarProfesionales(string pNombre)
        {
            //IRfcFunction function = null; RfcDestination dest = null;
            ////InMemoryDestinationConfiguration dc = new InMemoryDestinationConfiguration();
            //List<PersonaBE> listaResult = new List<PersonaBE>();
            //try
            //{
            //    /*try
            //    {
            //        RfcDestinationManager.RegisterDestinationConfiguration(dc);
            //    }
            //    catch { }
            //    RfcDestination dest = RfcDestinationManager.GetDestination(this._connId);
            //     */
            //    dest = DALC.getDestination();
            //    function = dest.Repository.CreateFunction("ZWEB_LISTA_PROFESIONALES");
            //    function.SetValue("IM_NOMBRE", pNombre);
            //    function.Invoke(dest);

            //    IRfcTable T_PA0001 = function.GetTable("T_PA0001");

            //    foreach (IRfcStructure item in T_PA0001)
            //    {
            //        PersonaBE obj = new PersonaBE();
            //        obj.CodPersona = item["PERNR"].GetString();
            //        obj.Descripcion = item["ENAME"].GetString();

            //        listaResult.Add(obj);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}
            //finally
            //{
            //    //RfcDestinationManager.UnregisterDestinationConfiguration(dc);
            //}
            //return listaResult;
            return null;
        }

        public PersonaBE leer(string pCodPersona)
        {
            //IRfcFunction function = null; RfcDestination dest = null;
            ////InMemoryDestinationConfiguration dc = new InMemoryDestinationConfiguration();
            //PersonaBE obj = null;
            //try
            //{
            //    /*try
            //    {
            //        RfcDestinationManager.RegisterDestinationConfiguration(dc);
            //    }
            //    catch { }
            //    RfcDestination dest = RfcDestinationManager.GetDestination(this._connId);
            //    */
            //    dest = DALC.getDestination();
            //    function = dest.Repository.CreateFunction("ZWEB_LEE_PERSONA");
            //    function.SetValue("IM_PERNR", pCodPersona);
            //    function.SetValue("IM_DNI", pCodPersona);
                
            //    function.Invoke(dest);

            //    IRfcTable PA0002 = function.GetTable("T_PA0002");
                                
            //    foreach (IRfcStructure item in PA0002)
            //    {
            //        obj = new PersonaBE();
                    
            //        obj.CodPersona = item["PERNR"].GetString();
            //        obj.Nombre = item["VORNA"].GetString();
            //        obj.Apellido = item["NACHN"].GetString();
            //        obj.ApeSoltero = item["NAME2"].GetString();
            //        obj.Iniciales = item["INITS"].GetString();
            //        obj.Descripcion = (item["VORNA"].GetString() + " " + item["NACHN"].GetString() + " " + item["NAME2"].GetString()).Trim();
            //        obj.Dni = item["RUFNM"].GetString();
            //        obj.Telefono = item["TITEL"].GetString();
            //    }
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}
            //finally {
            //    //RfcDestinationManager.UnregisterDestinationConfiguration(dc);
            //}
            //return obj;
            return null;
        }

        public void getInfoUsuario(string pCodPersona, out string pCodOfVtas, out string pCodGrupoVend)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
